package com.tuo51.childcare.repository;

import com.tuo51.childcare.domain.carestore.StoreItem;
import com.tuo51.childcare.domain.carestore.StoreItemCategory;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@CacheConfig(cacheNames = "ArticleCategoryRepository")
public interface StoreItemCategoryRepository extends JpaRepository<StoreItemCategory, String>, JpaSpecificationExecutor<StoreItemCategory> {

    @Cacheable(keyGenerator = "keyGenerator")
    List<StoreItemCategory> findAllByChannelAndDeletedIsFalseAndParentIsNullOrderByOrderWeightDesc(String channel);

    @Cacheable(keyGenerator = "keyGenerator")
    List<StoreItemCategory> findAllByChannelAndDeletedIsFalseAndParentIsNullAndHiddenIsFalseOrderByOrderWeightDesc(String channel);

    @Cacheable(keyGenerator = "keyGenerator")
    StoreItemCategory findByTitleAndChannelAndParentIdAndDeletedIsFalse(String title, String channel, String parentId);

    @Cacheable(keyGenerator = "keyGenerator")
    StoreItemCategory findByTitleAndChannelAndParentIdIsNullAndDeletedIsFalse(String title, String channel);

    @Cacheable(keyGenerator = "keyGenerator")
    StoreItemCategory findByStaticCodeAndDeletedIsFalse(String staticCode);

    List<StoreItemCategory> findAllByOrderByCreatedDesc();
}
